{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>
<form class="layui-form" action="" id="cross_srh">
    <div class="proxy_srh">
        <div class="layui-inline">
            <div class="layui-inline">

                <div class="layui-input-inline">
                    <label class="layui-form-label">任务别名：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="task_name" id="task_name" placeholder="请输入"
                               style="width:212px">
                    </div>
                </div>

                <div class="layui-input-inline">
                    <label class="layui-form-label">开始时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="t1" id="t1" placeholder="请输入" style="width:212px">
                    </div>

                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">结束时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="t2" id="t2" placeholder="请输入" style="width:212px">
                    </div>

                </div>

                <div class="layui-inline" style="left: 257px">
                    <button class="layui-btn" type="button" id="start" lay-submit lay-filter="start">查询</button>
                </div>
            </div>
        </div>

    </div>
</form>
<hr class="layui-bg-gray">
<!--<button class="layui-btn layui-btn-normal layui-btn-danger" id="delete" type="button">-->
<!--<i class="layui-icon"></i> 删除-->
<!--</button>-->
<script type="text/html" id="filemange_v1">
    <button type="button"  class="layui-btn layui-btn-xs layui-btn-danger" lay-event="getNode">查看趋势</button>
    <button type="button"  class="layui-btn layui-btn-primary layui-btn-xs" lay-event="addnote">备注</button>
</script>

<table class="layui-hide" id="boomerCase" lay-filter="boomerCase"></table>
<script>
    layui.use(['table','code'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var loading = layer.load();
          var  options = {
                elem:'#boomerCase',
                skin:"line",
                page:true,
                height: 'full-200',
                toolbar: true,
                url:'/result/search?',
                limit:10,
                limits:[10,20,30],
                where:{
                    task_name : $('#task_name').val(),
                    start_time:$('#t1').val(),
                    end_time:$('#t2').val(),
                },
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                cols:[[
                      {field: 'id', title: 'id',sort:true,width:80}
                      ,{field: 'task_name', title: 'task_name',sort:true}
                      ,{field: 'avg_response_time', title: 'avg',sort:true}
                      ,{field: 'max_response_time', title: 'max',sort:true}
                      ,{field: 'median_response_time', title: 'median',sort:true}
                      ,{field: 'current_rps', title: 'rps',sort:true}
                      ,{field: 'user_count', title: 'user',sort:true}
                      ,{field: 'errors_count', title: 'errors',sort:true}
                      ,{field: 'num_requests', title: 'n_reqs',sort:true}
                      ,{field: 'num_failures', title: 'n_fails',sort:true}
                      ,{field: 'result_json', title: 'result',templet: function(d){
                            jStr =  JSON.stringify(d.result_json, null, 4);
                            return jStr;
                      }}
                      ,{field: 'last_time', title: 'last_time',sort:true}
                      ,{fixed: 'right', title:'', toolbar: '#filemange_v1',width:150}

                ]],
                id:'caseBoomer',
                done:function(res,cur,count){
                    //$("[data-field='nodeId']").css('display','none');
                    layer.close(loading);
                }
              };

          var tableIns = table.render(options);

          table.on('row(boomerCase)', function(obj){
                obj.tr.css("background","#eeeeee");
          });
          table.on('rowDouble(boomerCase)', function(obj){
            msg = JSON.stringify(obj.data.result_json, null, 4);

            layer.open({
              title: '结果',
              area:['1055px','473px']
              ,content: '<pre>'+msg+'</pre>'
              ,closeBtn:1,
              shade: 0,
              shadeClose:true
            });

          });

          table.on('tool(boomerCase)', function(obj){

                if(obj.event === 'addnote'){
                    layui.data('test', {key: 'task_name',value: obj.data.task_name});
                    layer.open({
                            type:2,
                            content:"/load/result/history/remark",
                            area:['1055px','493px'],
                            //offset: ['231px','307px'],
                            title:obj.data.task_name + "——备注",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            maxmin: true,
                            cancel: function(index, layero){

                            }
                     });

                }else if(obj.event === 'getNode'){
                    //跳转到一个新页面
                    layui.data('test', {key: 'task_name',value: obj.data.task_name});
                    index = layer.open({
                            type:2,
                            content:"/load/result/history",
                            area:['1055px','473px'],
                            //offset: ['231px','307px'],
                            title:obj.data.task_name + "——历史趋势",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            maxmin: true,

                            cancel: function(index, layero){

                            }
                     });
                     layer.full(index);

                }else if(obj.event==='delNode'){

                }
          });
          //点击查询
          $('#start').on('click',function(){
              var loading = layer.load();

              options = {
                elem:'#boomerCase',
                skin:"line",
                toolbar: true,
                height: 'full-200',
                page:true,
                url:'/result/search?',
                limit:10,
                limits:[10,20,30],
                where:{
                    task_name : $('#task_name').val(),
                    start_time:$('#t1').val(),
                    end_time:$('#t2').val(),
                }
              }
              tableIns.reload(options);
              layer.close(loading);
          });

          form.render();
          layer.close(loading);
    });



</script>
<script>
//时间控件
layui.use('laydate', function(){
  var laydate = layui.laydate;
  laydate.render({
    elem: '#t1',
    type:'datetime',
    format:'yyyy-MM-dd HH:mm:ss',
  });
  laydate.render({
    elem: '#t2',
    type:'datetime',
    format:'yyyy-MM-dd HH:mm:ss',
  });

});


</script>

{% endblock %}